package com.tanhua.server.controller;

import com.tanhua.model.dto.ReplyDto;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 根据环信ID查询用户详细信息
     */
    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId) {
        UserInfoVo vo = messagesService.findUserInfoByHuanxin(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 添加好友
     *
     * @param replyDto
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity addFriend(@RequestBody ReplyDto replyDto) {
        //获取回复的id和回复信息
        Long friendId = Long.valueOf(replyDto.getUserId().toString());
        messagesService.addFriend(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询好友列表
     * 传入分页数据 可能还有昵称参数keyword
     */
    @GetMapping("/contacts")
    public ResponseEntity findFriends(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize
            , String keyword) {
        //调用Service查询好友分页数据
        PageResult pr = messagesService.findFriends(page, pagesize, keyword);
        return ResponseEntity.ok(pr);
    }


}